package io.guangli.tutorials1v1vcall

import android.content.Intent
import io.guangli.tutorials1v1vcall.Util.getToken
import androidx.appcompat.app.AppCompatActivity
import android.widget.EditText
import android.os.Bundle
import android.text.TextUtils
import android.widget.Toast
import io.guangli.tutorials1v1vcall.httpcomponent.OkGoStringCallBack
import android.view.View
import com.blankj.utilcode.util.LogUtils

class MainActivity : AppCompatActivity() {
    var editText: EditText? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        editText = findViewById(R.id.edit_content)
//        editText?.setText("test")
    }

    fun toVideo(view: View?) {
        val channelName = editText!!.text.toString()
        if (TextUtils.isEmpty(channelName)) {
            Toast.makeText(this, "请输入房间号", Toast.LENGTH_SHORT).show()
            return
        }
        getToken(
            channelName,
            object : OkGoStringCallBack<ChannelBean>(this, ChannelBean::class.java, false) {
                override fun onSuccess2Bean(bean: ChannelBean?) {
                    LogUtils.e(bean)
                    val intent = Intent(this@MainActivity, VideoChatViewActivity::class.java)
                    intent.putExtra("channelName", channelName)
                    intent.putExtra("token", bean?.data?.token)
                    intent.putExtra("roomUuid", bean?.data?.uuid)
                    startActivity(intent)
                }
            })
    }
}